package com.weiz.sso.controller;

import com.weiz.sso.entity.ReturnResult;
import com.weiz.sso.entity.User;
import com.weiz.sso.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 类功能简述：
 * 类功能详述：
 *
 * @author weiz
 */
@Controller
@RequestMapping("/sso")
public class AuthController {

    private TokenService service;

    @Autowired
    public AuthController(TokenService service) {
        this.service = service;
    }

    @RequestMapping({"/","/index"})
    public String index(){
        return "index";
    }

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult login(@RequestBody User user) {
        String token = service.login(user);
        return ReturnResult.successResult(token);
    }

    @RequestMapping("/checkJwt")
    @ResponseBody
    public ReturnResult checkJwt(String token) {
        return ReturnResult.successResult(service.checkJwt(token));
    }

    @RequestMapping("/refreshJwt")
    @ResponseBody
    public ReturnResult refreshJwt(String token){
        return ReturnResult.successResult(service.refreshJwt(token));
    }

    @RequestMapping("/inValid")
    @ResponseBody
    public ReturnResult inValid(String token) {
        service.inValid(token);
        return ReturnResult.successResult(null);
    }
}
